package com.zhangtai.modules.dao;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhangtai.modules.dto.UserBankCardDto;
import com.zhangtai.modules.entity.salary.UserBankCardEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 员工银行卡 记录
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2020-09-07 19:52:13
 */
@Mapper
public interface UserBankCardDao extends BaseMapper<UserBankCardEntity> {


    @Select("<script>SELECT COUNT(*) FROM tb_user_bank_card WHERE status = 1 " +
            "<if test='orgIds!=null and orgIds.size>0'> and unit_id in " +
            " <foreach item=\"orgId\" index=\"index\" collection=\"orgIds\" open=\"(\" separator=\",\" close=\")\">#{orgId}</foreach>" +
            "</if>"+
            "<if test='orgIds==null or orgIds.size==0'> and unit_id = null </if></script>" )
            public Integer getUserBankCardChangeNumber( @Param("orgIds") List<Long> orgIds);

    @Select("<script>SELECT	UBC.*,EL.CODE,EL.NAME,EL.org_id,EL.orgname,	EL.unit_id uid,	EL.unitname,"+
            "EL.job_id,	EL.jobname,	EL.job_Level_id,EL.job_level,EL.job_level_type "+
            "FROM   tb_user_bank_card UBC "+
            " LEFT JOIN tb_employee_info EL ON EL.oid = UBC.oid " +
            "<where> UBC.is_delete = 0 " +

            "<if test='orgIds!=null and orgIds.size>0'> and UBC.unit_id in " +
            " <foreach item=\"orgId\" index=\"index\" collection=\"orgIds\" open=\"(\" separator=\",\" close=\")\">#{orgId}</foreach>" +
            "</if>"+
            "<if test='orgIds==null or orgIds.size==0'> and UBC.unit_id = null </if>" +

            "<if test='name!=null'> and UBC.create_name like '%${name}%'</if>" +
            "<if test='code!=null'> and  EL.code like '%${code}%'  </if>" +
            "<if test='orgname!=null'> and EL.orgname like '%${orgname}%'  </if>" +
            "<if test='unitname!=null'> and  EL.unitname like '%${unitname}%'  </if>" +
            "<if test='jobname!=null'> and EL.jobname like '%${jobname}%'  </if>" +
            "<if test='status!=null'> and UBC.status = #{status}  </if>" +
            "<if test='status==null'> and (UBC.status = 2 or UBC.status = 3 ) </if>" +
            "</where>  ORDER BY UBC.update_time DESC" +
            "</script>")
    public List<UserBankCardDto> getUserBankCardPage( @Param("orgIds") List<Long> orgIds,
                                                         @Param("name") String name,
                                                        @Param("code") String code,
                                                        @Param("orgname") String orgname,
                                                        @Param("unitname") String unitname,
                                                        @Param("jobname") String jobname,
                                                        @Param("status") Integer status,
                                                        Page<UserBankCardDto> page);


}
